﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using NetROS.Tiers.Entities;
using NetROS.Tiers.Data;

#endregion

namespace NetROS.Tiers.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="VwKontoProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class VwKontoProviderBaseCore : EntityViewProviderBase<VwKonto>
	{
		#region Custom Methods
		
		
		#region _vwKonto_Get_KontoList_Za_Datum_Analiticki
		
		/// <summary>
		///	This method wrap the '_vwKonto_Get_KontoList_Za_Datum_Analiticki' stored procedure. 
		/// </summary>
		/// <param name="Datum"> A <c>System.DateTime?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="VList&lt;VwKonto&gt;"/> instance.</returns>
		public VList<VwKonto> Get_KontoList_Za_Datum_Analiticki(System.DateTime? @Datum)
		{
			return Get_KontoList_Za_Datum_Analiticki(null, 0, int.MaxValue , @Datum);
		}
		
		/// <summary>
		///	This method wrap the '_vwKonto_Get_KontoList_Za_Datum_Analiticki' stored procedure. 
		/// </summary>
		/// <param name="Datum"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="VList&lt;VwKonto&gt;"/> instance.</returns>
		public VList<VwKonto> Get_KontoList_Za_Datum_Analiticki(int start, int pageLength, System.DateTime? @Datum)
		{
			return Get_KontoList_Za_Datum_Analiticki(null, start, pageLength , @Datum);
		}
				
		/// <summary>
		///	This method wrap the '_vwKonto_Get_KontoList_Za_Datum_Analiticki' stored procedure. 
		/// </summary>
		/// <param name="Datum"> A <c>System.DateTime?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <returns>A <see cref="VList&lt;VwKonto&gt;"/> instance.</returns>
		public VList<VwKonto> Get_KontoList_Za_Datum_Analiticki(TransactionManager transactionManager, System.DateTime? @Datum)
		{
			return Get_KontoList_Za_Datum_Analiticki(transactionManager, 0, int.MaxValue , @Datum);
		}
		
		/// <summary>
		///	This method wrap the '_vwKonto_Get_KontoList_Za_Datum_Analiticki' stored procedure. 
		/// </summary>
		/// <param name="Datum"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="VList&lt;VwKonto&gt;"/> instance.</returns>
		public abstract VList<VwKonto> Get_KontoList_Za_Datum_Analiticki(TransactionManager transactionManager, int start, int pageLength , System.DateTime? @Datum);
		
		#endregion
		
		#region _vwKonto_GetByID
		
		/// <summary>
		///	This method wrap the '_vwKonto_GetByID' stored procedure. 
		/// </summary>
		/// <param name="ID"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="VList&lt;VwKonto&gt;"/> instance.</returns>
		public VList<VwKonto> GetByID(System.Int32? @ID)
		{
			return GetByID(null, 0, int.MaxValue , @ID);
		}
		
		/// <summary>
		///	This method wrap the '_vwKonto_GetByID' stored procedure. 
		/// </summary>
		/// <param name="ID"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="VList&lt;VwKonto&gt;"/> instance.</returns>
		public VList<VwKonto> GetByID(int start, int pageLength, System.Int32? @ID)
		{
			return GetByID(null, start, pageLength , @ID);
		}
				
		/// <summary>
		///	This method wrap the '_vwKonto_GetByID' stored procedure. 
		/// </summary>
		/// <param name="ID"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <returns>A <see cref="VList&lt;VwKonto&gt;"/> instance.</returns>
		public VList<VwKonto> GetByID(TransactionManager transactionManager, System.Int32? @ID)
		{
			return GetByID(transactionManager, 0, int.MaxValue , @ID);
		}
		
		/// <summary>
		///	This method wrap the '_vwKonto_GetByID' stored procedure. 
		/// </summary>
		/// <param name="ID"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="VList&lt;VwKonto&gt;"/> instance.</returns>
		public abstract VList<VwKonto> GetByID(TransactionManager transactionManager, int start, int pageLength , System.Int32? @ID);
		
		#endregion
		
		#region _vwKonto_Get_KontoList_Za_Datum
		
		/// <summary>
		///	This method wrap the '_vwKonto_Get_KontoList_Za_Datum' stored procedure. 
		/// </summary>
		/// <param name="Datum"> A <c>System.DateTime?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="VList&lt;VwKonto&gt;"/> instance.</returns>
		public VList<VwKonto> Get_KontoList_Za_Datum(System.DateTime? @Datum)
		{
			return Get_KontoList_Za_Datum(null, 0, int.MaxValue , @Datum);
		}
		
		/// <summary>
		///	This method wrap the '_vwKonto_Get_KontoList_Za_Datum' stored procedure. 
		/// </summary>
		/// <param name="Datum"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="VList&lt;VwKonto&gt;"/> instance.</returns>
		public VList<VwKonto> Get_KontoList_Za_Datum(int start, int pageLength, System.DateTime? @Datum)
		{
			return Get_KontoList_Za_Datum(null, start, pageLength , @Datum);
		}
				
		/// <summary>
		///	This method wrap the '_vwKonto_Get_KontoList_Za_Datum' stored procedure. 
		/// </summary>
		/// <param name="Datum"> A <c>System.DateTime?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <returns>A <see cref="VList&lt;VwKonto&gt;"/> instance.</returns>
		public VList<VwKonto> Get_KontoList_Za_Datum(TransactionManager transactionManager, System.DateTime? @Datum)
		{
			return Get_KontoList_Za_Datum(transactionManager, 0, int.MaxValue , @Datum);
		}
		
		/// <summary>
		///	This method wrap the '_vwKonto_Get_KontoList_Za_Datum' stored procedure. 
		/// </summary>
		/// <param name="Datum"> A <c>System.DateTime?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="VList&lt;VwKonto&gt;"/> instance.</returns>
		public abstract VList<VwKonto> Get_KontoList_Za_Datum(TransactionManager transactionManager, int start, int pageLength , System.DateTime? @Datum);
		
		#endregion
		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;VwKonto&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;VwKonto&gt;"/></returns>
		protected static VList&lt;VwKonto&gt; Fill(DataSet dataSet, VList<VwKonto> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<VwKonto>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;VwKonto&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<VwKonto>"/></returns>
		protected static VList&lt;VwKonto&gt; Fill(DataTable dataTable, VList<VwKonto> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					VwKonto c = new VwKonto();
					c.ID = (Convert.IsDBNull(row["ID"]))?(int)0:(System.Int32)row["ID"];
					c.Sifra = (Convert.IsDBNull(row["Sifra"]))?string.Empty:(System.String)row["Sifra"];
					c.Naziv = (Convert.IsDBNull(row["Naziv"]))?string.Empty:(System.String)row["Naziv"];
					c.Analiticki = (Convert.IsDBNull(row["Analiticki"]))?false:(System.Boolean)row["Analiticki"];
					c.AnalitickiDaNe = (Convert.IsDBNull(row["AnalitickiDaNe"]))?string.Empty:(System.String)row["AnalitickiDaNe"];
					c.IDTip = (Convert.IsDBNull(row["IDTip"]))?(int)0:(System.Int32)row["IDTip"];
					c.IDKontoPoreza = (Convert.IsDBNull(row["IDKontoPoreza"]))?(int)0:(System.Int32?)row["IDKontoPoreza"];
					c.DatumOd = (Convert.IsDBNull(row["DatumOd"]))?DateTime.MinValue:(System.DateTime)row["DatumOd"];
					c.DatumDo = (Convert.IsDBNull(row["DatumDo"]))?DateTime.MinValue:(System.DateTime?)row["DatumDo"];
					c.TipKontaNaziv = (Convert.IsDBNull(row["TipKontaNaziv"]))?string.Empty:(System.String)row["TipKontaNaziv"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;VwKonto&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;VwKonto&gt;"/></returns>
		protected VList<VwKonto> Fill(IDataReader reader, VList<VwKonto> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					VwKonto entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<VwKonto>("VwKonto",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new VwKonto();
					}
					entity.ID = (System.Int32)reader["ID"];
					//entity.ID = (Convert.IsDBNull(reader["ID"]))?(int)0:(System.Int32)reader["ID"];
					entity.Sifra = (System.String)reader["Sifra"];
					//entity.Sifra = (Convert.IsDBNull(reader["Sifra"]))?string.Empty:(System.String)reader["Sifra"];
					entity.Naziv = (System.String)reader["Naziv"];
					//entity.Naziv = (Convert.IsDBNull(reader["Naziv"]))?string.Empty:(System.String)reader["Naziv"];
					entity.Analiticki = (System.Boolean)reader["Analiticki"];
					//entity.Analiticki = (Convert.IsDBNull(reader["Analiticki"]))?false:(System.Boolean)reader["Analiticki"];
					entity.AnalitickiDaNe = (System.String)reader["AnalitickiDaNe"];
					//entity.AnalitickiDaNe = (Convert.IsDBNull(reader["AnalitickiDaNe"]))?string.Empty:(System.String)reader["AnalitickiDaNe"];
					entity.IDTip = (System.Int32)reader["IDTip"];
					//entity.IDTip = (Convert.IsDBNull(reader["IDTip"]))?(int)0:(System.Int32)reader["IDTip"];
					entity.IDKontoPoreza = reader.IsDBNull(reader.GetOrdinal("IDKontoPoreza")) ? null : (System.Int32?)reader["IDKontoPoreza"];
					//entity.IDKontoPoreza = (Convert.IsDBNull(reader["IDKontoPoreza"]))?(int)0:(System.Int32?)reader["IDKontoPoreza"];
					entity.DatumOd = (System.DateTime)reader["DatumOd"];
					//entity.DatumOd = (Convert.IsDBNull(reader["DatumOd"]))?DateTime.MinValue:(System.DateTime)reader["DatumOd"];
					entity.DatumDo = reader.IsDBNull(reader.GetOrdinal("DatumDo")) ? null : (System.DateTime?)reader["DatumDo"];
					//entity.DatumDo = (Convert.IsDBNull(reader["DatumDo"]))?DateTime.MinValue:(System.DateTime?)reader["DatumDo"];
					entity.TipKontaNaziv = (System.String)reader["TipKontaNaziv"];
					//entity.TipKontaNaziv = (Convert.IsDBNull(reader["TipKontaNaziv"]))?string.Empty:(System.String)reader["TipKontaNaziv"];
					entity.AcceptChanges();
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="VwKonto"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="VwKonto"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, VwKonto entity)
		{
			reader.Read();
			entity.ID = (System.Int32)reader["ID"];
			//entity.ID = (Convert.IsDBNull(reader["ID"]))?(int)0:(System.Int32)reader["ID"];
			entity.Sifra = (System.String)reader["Sifra"];
			//entity.Sifra = (Convert.IsDBNull(reader["Sifra"]))?string.Empty:(System.String)reader["Sifra"];
			entity.Naziv = (System.String)reader["Naziv"];
			//entity.Naziv = (Convert.IsDBNull(reader["Naziv"]))?string.Empty:(System.String)reader["Naziv"];
			entity.Analiticki = (System.Boolean)reader["Analiticki"];
			//entity.Analiticki = (Convert.IsDBNull(reader["Analiticki"]))?false:(System.Boolean)reader["Analiticki"];
			entity.AnalitickiDaNe = (System.String)reader["AnalitickiDaNe"];
			//entity.AnalitickiDaNe = (Convert.IsDBNull(reader["AnalitickiDaNe"]))?string.Empty:(System.String)reader["AnalitickiDaNe"];
			entity.IDTip = (System.Int32)reader["IDTip"];
			//entity.IDTip = (Convert.IsDBNull(reader["IDTip"]))?(int)0:(System.Int32)reader["IDTip"];
			entity.IDKontoPoreza = reader.IsDBNull(reader.GetOrdinal("IDKontoPoreza")) ? null : (System.Int32?)reader["IDKontoPoreza"];
			//entity.IDKontoPoreza = (Convert.IsDBNull(reader["IDKontoPoreza"]))?(int)0:(System.Int32?)reader["IDKontoPoreza"];
			entity.DatumOd = (System.DateTime)reader["DatumOd"];
			//entity.DatumOd = (Convert.IsDBNull(reader["DatumOd"]))?DateTime.MinValue:(System.DateTime)reader["DatumOd"];
			entity.DatumDo = reader.IsDBNull(reader.GetOrdinal("DatumDo")) ? null : (System.DateTime?)reader["DatumDo"];
			//entity.DatumDo = (Convert.IsDBNull(reader["DatumDo"]))?DateTime.MinValue:(System.DateTime?)reader["DatumDo"];
			entity.TipKontaNaziv = (System.String)reader["TipKontaNaziv"];
			//entity.TipKontaNaziv = (Convert.IsDBNull(reader["TipKontaNaziv"]))?string.Empty:(System.String)reader["TipKontaNaziv"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="VwKonto"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="VwKonto"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, VwKonto entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.ID = (Convert.IsDBNull(dataRow["ID"]))?(int)0:(System.Int32)dataRow["ID"];
			entity.Sifra = (Convert.IsDBNull(dataRow["Sifra"]))?string.Empty:(System.String)dataRow["Sifra"];
			entity.Naziv = (Convert.IsDBNull(dataRow["Naziv"]))?string.Empty:(System.String)dataRow["Naziv"];
			entity.Analiticki = (Convert.IsDBNull(dataRow["Analiticki"]))?false:(System.Boolean)dataRow["Analiticki"];
			entity.AnalitickiDaNe = (Convert.IsDBNull(dataRow["AnalitickiDaNe"]))?string.Empty:(System.String)dataRow["AnalitickiDaNe"];
			entity.IDTip = (Convert.IsDBNull(dataRow["IDTip"]))?(int)0:(System.Int32)dataRow["IDTip"];
			entity.IDKontoPoreza = (Convert.IsDBNull(dataRow["IDKontoPoreza"]))?(int)0:(System.Int32?)dataRow["IDKontoPoreza"];
			entity.DatumOd = (Convert.IsDBNull(dataRow["DatumOd"]))?DateTime.MinValue:(System.DateTime)dataRow["DatumOd"];
			entity.DatumDo = (Convert.IsDBNull(dataRow["DatumDo"]))?DateTime.MinValue:(System.DateTime?)dataRow["DatumDo"];
			entity.TipKontaNaziv = (Convert.IsDBNull(dataRow["TipKontaNaziv"]))?string.Empty:(System.String)dataRow["TipKontaNaziv"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region VwKontoFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwKonto"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwKontoFilterBuilder : SqlFilterBuilder<VwKontoColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwKontoFilterBuilder class.
		/// </summary>
		public VwKontoFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwKontoFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwKontoFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwKontoFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwKontoFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwKontoFilterBuilder

	#region VwKontoParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwKonto"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwKontoParameterBuilder : ParameterizedSqlFilterBuilder<VwKontoColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwKontoParameterBuilder class.
		/// </summary>
		public VwKontoParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwKontoParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwKontoParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwKontoParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwKontoParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwKontoParameterBuilder
} // end namespace
